﻿/// <reference path="_namespace.js" />
/// <reference path="Colour.js" />
/// <reference path="../math/Vector3.js" />
/// <reference path="LightTypes.js" />

$imports("ajax.math.Vector3");
$imports("ajax.drawing.Colour");
$imports("ajax.drawing.LightTypes");

ajax.drawing.Light = function(type, posdirVector3, diffuseColour, ambientColour, enabled)
{
    this.initialize(type, posdirVector3, diffuseColour, ambientColour, enabled);
    
}


// Finsh Light Class
ajax.drawing.Light.prototype = 
{
    type:  0,
    direction: ajax.math.Vector3.prototype,
    position: ajax.math.Vector3.prototype,    
    enabled                        : false,
    _ambient                       : new ajax.drawing.Colour(0, 0, 0),
    _rAmbientIntensity             : 0,
    _gAmbientIntensity             : 0,
    _bAmbientIntensity	           : 0,
    _diffuse                       : new ajax.drawing.Colour(255, 255, 255),
    _rDiffuseIntensity             : 0,
    _gDiffuseIntensity             : 0,
    _bDiffuseIntensity             : 0,    
    
    getRAmbientIntensity            : function() { return this._rAmbientIntensity; },
    getGAmbientIntensity            : function() { return this._gAmbientIntensity; },
    getBAmbientIntensity            : function() { return this._bAmbientIntensity; },
    
    getRDiffuseIntensity            : function(){ return this._rDiffuseIntensity; },
    getGDiffuseIntensity            : function(){ return this._gDiffuseIntensity; },
    getBDiffuseIntensity            : function(){ return this._bDiffuseIntensity; },
    
    getAmbient                      : function()
    {///<returns type="ajax.drawing.Colour"/>
        return this._ambient;
    },
    setAmbient                      : function(value)
    {///<param name="value" type="ajax.drawing.Colour"/>
        _ambient = value;
        // Store the intensity values
        this._rAmbientIntensity = parseFloat(value.r/255);
        this._gAmbientIntensity = parseFloat(value.g/255);
        this._bAmbientIntensity = parseFloat(value.b/255);
    },
    
    getDiffuse                      : function()
    {///<returns type="ajax.drawing.Colour"/>
        return this._diffuse;
    },
    setDiffuse                      : function(value)
    {
        this._diffuse = value; 
        // Store the intensity values
        this._rDiffuseIntensity = parseFloat(value.r/255);
        this._gDiffuseIntensity = parseFloat(value.g/255);
        this._bDiffuseIntensity = parseFloat(value.b/255);
    }        
}

ajax.drawing.Light.cast = function(obj)
{///<returns type="ajax.drawing.Light"/>
    return obj;
}

ajax.drawing.Light.prototype.initialize = function(type, posdirVector3, diffuseColour, ambientColour, enabled)
{///<param name="type" type="number" integer="true"/>
        
    // If the light is directional then set its direction as well
    if (type == ajax.drawing.LightTypes.Directional)
        this.direction = posdirVector3;
    else if (type == ajax.drawing.LightTypes.Omni)
        this.position = posdirVector3;
    
    // Store the light type
    this.type = type;
    // Set the colours
    this.setDiffuse(diffuseColour);
    this.setAmbient(ambientColour);
    
    this.enabled = enabled;
    
}